load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("//build:STRINGER.bzl", "stringer")
load("//pkg/testutils:buildutil/buildutil.bzl", "disallowed_imports_test")

go_library(
    name = "tree",
    srcs = [
        "adjust_constants.go",
        "alter_backup.go",
        "alter_backup_schedule.go",
        "alter_changefeed.go",
        "alter_database.go",
        "alter_default_privileges.go",
        "alter_index.go",
        "alter_range.go",
        "alter_role.go",
        "alter_schema.go",
        "alter_sequence.go",
        "alter_table.go",
        "alter_tenant.go",
        "alter_type.go",
        "analyze.go",
        "annotation.go",
        "backup.go",
        "batch.go",
        "call.go",
        "changefeed.go",
        "col_name.go",
        "comment_on_column.go",
        "comment_on_constraint.go",
        "comment_on_database.go",
        "comment_on_index.go",
        "comment_on_schema.go",
        "comment_on_table.go",
        "comment_on_type.go",
        "compare.go",
        "constant.go",
        "constant_eval.go",
        "constants.go",
        "constraint.go",
        "copy.go",
        "create.go",
        "create_logical_replication.go",
        "create_routine.go",
        "create_trigger.go",
        "cursor.go",
        "data_placement.go",
        "datum.go",
        "datum_alloc.go",
        "decimal.go",
        "delete.go",
        "discard.go",
        "drop.go",
        "drop_owned_by.go",
        "eval.go",
        "eval_binary_ops.go",
        "eval_unary_ops.go",
        "explain.go",
        "export.go",
        "expr.go",
        "format.go",
        "format_fingerprint.go",
        "function_definition.go",
        "function_name.go",
        "grant.go",
        "import.go",
        "indexed_vars.go",
        "insert.go",
        "name_part.go",
        "name_resolution.go",
        "object_name.go",
        "overload.go",
        "parse_array.go",
        "parse_string.go",  # keep
        "parse_tuple.go",
        "persistence.go",
        "pgwire_encode.go",
        "placeholders.go",
        "prepare.go",
        "pretty.go",
        "reassign_owned_by.go",
        "regexp_cache.go",
        "region.go",
        "rename.go",
        "returning.go",
        "revoke.go",
        "role_spec.go",
        "routine.go",
        "run_control.go",
        "schedule.go",
        "schema_feature_name.go",
        "scrub.go",
        "select.go",
        "set.go",
        "show.go",
        "split.go",
        "stmt.go",
        "survival_goal.go",
        "table_name.go",
        "table_pattern.go",
        "table_ref.go",
        "tenant.go",
        "tenant_settings.go",
        "testutils.go",
        "time.go",
        "truncate.go",
        "txn.go",
        "type_check.go",
        "type_name.go",
        "typing.go",
        "union.go",
        "unlisten.go",
        "unsupported_error.go",
        "update.go",
        "values.go",
        "var_expr.go",
        "var_name.go",
        "walk.go",
        "with.go",
        "zone.go",
        ":eval-visitor",  # keep
        ":gen-createtypevariety-stringer",  # keep
        ":gen-statementreturntype-stringer",  # keep
        ":gen-statementtype-stringer",  # keep
    ],
    importpath = "github.com/cockroachdb/cockroach/pkg/sql/sem/tree",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/col/coldata",
        "//pkg/col/typeconv",  # keep
        "//pkg/geo",
        "//pkg/geo/geopb",
        "//pkg/kv/kvserver/concurrency/isolation",
        "//pkg/sql/lex",
        "//pkg/sql/lexbase",
        "//pkg/sql/pgrepl/lsn",
        "//pkg/sql/pgwire/pgcode",
        "//pkg/sql/pgwire/pgerror",
        "//pkg/sql/privilege",
        "//pkg/sql/sem/cast",
        "//pkg/sql/sem/catconstants",
        "//pkg/sql/sem/catid",
        "//pkg/sql/sem/semenumpb",
        "//pkg/sql/sem/tree/treebin",
        "//pkg/sql/sem/tree/treecmp",
        "//pkg/sql/sem/tree/treewindow",
        "//pkg/sql/sem/volatility",
        "//pkg/sql/sessiondatapb",
        "//pkg/sql/types",
        "//pkg/util",
        "//pkg/util/bitarray",
        "//pkg/util/buildutil",
        "//pkg/util/cache",
        "//pkg/util/collatedstring",
        "//pkg/util/duration",
        "//pkg/util/encoding",
        "//pkg/util/errorutil/unimplemented",
        "//pkg/util/intsets",
        "//pkg/util/ipaddr",
        "//pkg/util/iterutil",
        "//pkg/util/json",
        "//pkg/util/pretty",
        "//pkg/util/stringencoding",
        "//pkg/util/syncutil",
        "//pkg/util/timeofday",
        "//pkg/util/timetz",
        "//pkg/util/timeutil",
        "//pkg/util/timeutil/pgdate",
        "//pkg/util/tsearch",
        "//pkg/util/uint128",
        "//pkg/util/uuid",
        "//pkg/util/vector",
        "@com_github_cockroachdb_apd_v3//:apd",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_redact//:redact",
        "@com_github_google_go_cmp//cmp",
        "@com_github_lib_pq//oid",
        "@org_golang_x_text//collate",
        "@org_golang_x_text//language",
    ],
)

go_test(
    name = "tree_test",
    size = "small",
    srcs = [
        "col_types_test.go",
        "collatedstring_test.go",
        "compare_test.go",
        "constant_test.go",
        "create_routine_test.go",
        "datum_integration_test.go",
        "datum_invariants_test.go",
        "datum_prev_next_test.go",
        "datum_test.go",
        "expr_test.go",
        "format_test.go",
        "function_definition_test.go",
        "function_name_test.go",
        "helpers_test.go",
        "indexed_vars_test.go",
        "json_test.go",
        "main_test.go",
        "name_part_test.go",
        "name_resolution_test.go",
        "operators_test.go",
        "overload_test.go",
        "parse_array_test.go",
        "parse_string_test.go",
        "parse_tuple_test.go",
        "placeholders_test.go",
        "pretty_test.go",
        "table_name_test.go",
        "time_test.go",
        "txn_test.go",
        "type_check_internal_test.go",
        "type_check_test.go",
        "type_name_test.go",
        "typing_test.go",
        "var_expr_test.go",
    ],
    data = glob(["testdata/**"]) + ["//pkg/sql/parser:sql.y"],
    embed = [":tree"],
    deps = [
        "//pkg/build/bazel",
        "//pkg/col/coldata",
        "//pkg/col/coldataext",
        "//pkg/internal/rsg",
        "//pkg/kv/kvserver/concurrency/isolation",
        "//pkg/security/securityassets",
        "//pkg/security/securitytest",
        "//pkg/settings/cluster",
        "//pkg/sql/colconv",
        "//pkg/sql/parser",
        "//pkg/sql/randgen",
        "//pkg/sql/sem/builtins",
        "//pkg/sql/sem/catid",
        "//pkg/sql/sem/eval",
        "//pkg/sql/sem/normalize",
        "//pkg/sql/sem/tree/treebin",
        "//pkg/sql/sem/tree/treecmp",
        "//pkg/sql/sem/volatility",
        "//pkg/sql/sessiondata",
        "//pkg/sql/sessiondatapb",
        "//pkg/sql/types",
        "//pkg/testutils",
        "//pkg/testutils/datapathutils",
        "//pkg/testutils/sqlutils",
        "//pkg/util/duration",
        "//pkg/util/json",
        "//pkg/util/leaktest",
        "//pkg/util/log",
        "//pkg/util/pretty",
        "//pkg/util/randutil",
        "//pkg/util/timeofday",
        "//pkg/util/timetz",
        "//pkg/util/timeutil",
        "//pkg/util/timeutil/pgdate",
        "@com_github_cockroachdb_apd_v3//:apd",
        "@com_github_lib_pq//oid",
        "@com_github_stretchr_testify//assert",
        "@com_github_stretchr_testify//require",
        "@org_golang_x_sync//errgroup",
    ],
)

stringer(
    name = "gen-createtypevariety-stringer",
    src = "create.go",
    typ = "CreateTypeVariety",
)

stringer(
    name = "gen-statementreturntype-stringer",
    src = "stmt.go",
    typ = "StatementReturnType",
)

stringer(
    name = "gen-statementtype-stringer",
    src = "stmt.go",
    typ = "StatementType",
)

eval_generated = [
    "eval_expr_generated.go",
    "eval_op_generated.go",
]

genrule(
    name = "eval-visitor",
    srcs = glob(
        ["*.go"],
        exclude = eval_generated,
    ),
    outs = eval_generated,
    cmd = "$(location //pkg/sql/sem/tree/evalgen) --out $(@D) $(SRCS)",
    tools = ["//pkg/sql/sem/tree/evalgen"],
    visibility = [
        ":__pkg__",
        "//pkg/gen:__pkg__",
    ],
)

disallowed_imports_test(
    "tree",
    disallowed_list = [
        "//pkg/kv",
        "//pkg/roachpb",
        "//pkg/security",
        "//pkg/server",
        "//pkg/sql/sessiondata",
        "//pkg/storage",
        "//pkg/util/log",
    ],
    disallowed_prefixes = [
        "pkg/sql/catalog",
    ],
)
